﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Tour.BLL;
using Tour.DAL;

public partial class Modules_Tour_TourImageAE : VST.Controls.BaseLCGPage
{
    public int? TourImageId { get; set; }
    public int? TourId { get; set; }
    protected void Page_Load(object sender, EventArgs e)
    {
        TourImageId = CommonHelper.QueryStringInt("TourImageId", null);
        TourId = CommonHelper.QueryStringInt("TourId", null);
        if (!TourId.HasValue)
        {
            Response.Redirect("TourList.aspx");
        }
        if (!IsPostBack)
        {
            LoadData();
        }
    }
    void LoadData()
    {
        if (TourImageId.HasValue)
        {
            TblTourImageEntity item = TblTourImageManager.CreateInstant().SelectOne(TourImageId.Value);
            txtName.Text = item.Name;
            imgThumb.ImageUrl = item.ImageUrl;
            hdfimgImageTour.Value = item.ImageUrl;
        }
    }

    TblTourImageEntity GetTblTourImage()
    {
        TblTourImageEntity item = new TblTourImageEntity();
        if (TourImageId.HasValue)
        {
            item = TblTourImageManager.CreateInstant().SelectOne(TourImageId.Value);
        }
        else
        {
            item.Id = 0;
            item.DisplayOrder = 50;
            item.CreatedDate = DateTime.Now;
        }
        item.TourId = TourId.Value;
        item.Name = txtName.Text;
        item.ImageUrl = hdfimgImageTour.Value;
        item.CreatedDate = DateTime.Now;
        return item;
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        TblTourImageManager.CreateInstant().InsertUpdate(GetTblTourImage());
        Response.Redirect("TourImageList.aspx?TourId=" + TourId);
    }
    private void UpdateOrderOffAndDelete(string strId, string strParentId, int NewIndex)
    {
        string Whereclause = " And TourId IS NULL ";
        if (!strParentId.Equals(""))
        {
            Whereclause = String.Format(" And TourId={0}", strParentId);
        }
        string Whereclause1 = String.Format(" ID={0}", strId);
        string Whereclause2 = String.Format(" And Id<>{0}", strId);
        Tools.SqlHelper.UpdateOrders("TblTourImage", Whereclause, Whereclause1, Whereclause2, NewIndex);
    }
}